<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Comment extends Front_Controller
{
	public static $m_arrTpl = array('info'=>'0','news'=>'1','cul'=>'2','strategy'=>'3','nous'=>'4','ask'=>'5');
	//public static $m_arrTpl = array('info'=>'0','news'=>'1','cul'=>'2','strategy'=>'3','nous'=>'4','ask'=>'5');
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form'));
		$this->load->model('front/Comment_mdl');
		$this->load->model('front/Strategy_mdl');
		
		$this->load->helper(array('form'));
		$this->load->model('front/Frontget_ml');
		$this->load->model('front/Search_m');		
		$this->siteSetings=$this->Frontget_ml->get_site_settings();	
		$this->announcement=$this->Frontget_ml->get_announcement();	
		$this->lineclass=$this->Frontget_ml->get_lineclass();
		$this->TicketClass=$this->Frontget_ml->getTicketClass();
		$this->newsclass=$this->Frontget_ml->get_newsclass();
		$this->tagsclass=$this->Frontget_ml->get_tagsclass();//获取攻略分类
		$this->des_tags=$this->Search_m->get_des_tags();	
		// $this->ModelClass=$this->Frontget_ml->getModelClass();	

		$current_title     = $this->siteSetings["site_description"];
		$this->m_arrPublic =   array("newsclass"=>$this->newsclass,"TicketClass"=>$this->TicketClass,"lineclass"=>$this->lineclass,"des_tags"=>$this->des_tags,"current_title"=>$current_title,"siteSetings"=>$this->siteSetings,"tagsclass"=>$this->tagsclass);
	}
	
	public function commentList()
	{
		$this->load->library('pagination');
		$model= $this->uri->segment(3);
		$p_id = $this->uri->segment(4);
		//$showType = $this->uri->segment(5);
		// print_r($model);
		// print_r($p_id);
		$config['base_url'] = site_url("/comment/commentList/$model/$p_id/");
		$type=0	;
		//$p_user,$p_content,$p_anon,$p_type 

		$total_rows  = $this->Comment_mdl->getCommentById(0,10,0,$p_id,$model);
		$config['total_rows']       = $total_rows;
		$config['per_page']         = 5;
		$config['uri_segment']      = 5;
		$config['full_tag_open']    = '';
		$config['full_tag_close']   = '';
		$config['cur_tag_open']     = '&nbsp;<span class="current">';
		$config['cur_tag_close']    = '</span>';
		$config['prev_link']        = '上一页';
		$config['next_link']        = '下一页';
		$config['first_link']       = ' 首页';
		$config['last_link']        = ' 尾页';
		$this->pagination->initialize($config);
		$begin_record = $this->uri->segment(5);
		if ($begin_record == null)
		{
			$begin_record = 0;
		}
		$type = 1;
		$arr['comment'] = $this->Comment_mdl->getCommentById($begin_record,$config['per_page'],$type,$p_id,$model);	
		// 分页END
	
		$data  = $arr + $this->m_arrPublic;
		
		$this->load->view('comment_list',$data);
	}
	
	public function singeComment($p_id)
	{
		$arr = $this->Comment_mdl->getcomment($p_id);
		$nextId = $this->Comment_mdl->getNextcommentIdById($p_id);
		$arrNext['next'] = $this->Comment_mdl->getComment($nextId);
		if (empty($arrNext['next']))
		{
			$arrNext['next'] = array('id' => 0,'comment_title' => '');
		}
		$data = $arr + $this->m_arrPublic + $arrNext;
		$this->load->view('comment_show',$data);
	}
	public function SaveComment()
	{
			$this->_SaveComment_post();
	}	
	public function _SaveComment_post()
	{
		//$p_user,$p_content,$p_anon,$p_type 
		$p_user      = $this->input->post("addUser");	//评论用户名称
		$p_content   = $this->input->post("mycontent1");	//评论内容
		$p_anon      = $this->input->post("cbIsNi");	//是否匿名
		$p_type      = $this->input->post("type");			//文章大分类
		$p_id     	 = $this->input->post("id");			//文章id
		$title     	 = $this->input->post("title");			//文章标题
	//	print_r($_POST);
		$status   	 = $this->Comment_mdl->setCommentById($p_id,$p_user,$p_content,$p_anon,$p_type,$title);
		//print_R($status);
	}
	public function commentListShow()
	{
		$this->load->library('pagination');
		$model= $this->uri->segment(3);
		$p_id = $this->uri->segment(4);
		// print_r($model);
		// print_r($p_id);
		$config['base_url'] = site_url("/comment/commentListShow/$model/$p_id/");
		$type=0	;
		//$p_user,$p_content,$p_anon,$p_type 

		$total_rows  = $this->Comment_mdl->getCommentById(0,10,0,$p_id,$model);
		$config['total_rows']       = $total_rows;
		$config['per_page']         = 15;
		$config['uri_segment']      = 5;
		$config['full_tag_open']    = '';
		$config['full_tag_close']   = '';
		$config['cur_tag_open']     = '&nbsp;<span class="current">';
		$config['cur_tag_close']    = '</span>';
		$config['prev_link']        = '上一页';
		$config['next_link']        = '下一页';
		$config['first_link']       = ' 首页';
		$config['last_link']        = ' 尾页';
		$this->pagination->initialize($config);
		$begin_record = $this->uri->segment(5);
		if ($begin_record == null)
		{
			$begin_record = 0;
		}
		$type = 1;
		$arr['comment'] = $this->Comment_mdl->getCommentById($begin_record,$config['per_page'],$type,$p_id,$model);	
		// 分页END
	
		$data  = $arr + $this->m_arrPublic;
		
		$this->load->view('comment_list2',$data);
	}
}
